package com.yanqu.road.server.logic.recharge.limit;

import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eCardType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.webservice.GamePublicFunction;

public class PrivilegeCardMallLimit extends BaseRMBMallLimit {
    public PrivilegeCardMallLimit(long userId, MallInfo mallInfo) {
        super(userId, mallInfo);
    }

    @Override
    protected boolean isSystemUnLock() {
        return GamePublicFunction.isSystemOpen(userId, eSystemId.PrivilegeCard.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        LimitBuyResult limitBuyResult = new LimitBuyResult();
        if(mallInfo.getMallId() == GameConfig.PRIVILEGE_WEEK_CARD_MALL_ID){
            limitBuyResult.setLimitCount(1);
        }else {
            limitBuyResult.setLimitCount(1);
        }
        return limitBuyResult;
    }

    @Override
    protected int logicCheck() {
        boolean canBuy = false;
        if (mallInfo.getMallId() == GameConfig.LIFE_CARD_MALL_ID || mallInfo.getMallId() == GameConfig.WEEK_CARD_MALL_ID) {
            int cardType;
            if (mallInfo.getMallId() == GameConfig.LIFE_CARD_MALL_ID) {
                cardType = eCardType.YearCard.getValue();
            } else {
                cardType = eCardType.MonthCard.getValue();
            }
            canBuy = GamePublicFunction.privilegeCardCanBuy(userId, cardType);
        }else if(mallInfo.getMallId() == GameConfig.PRIVILEGE_WEEK_CARD_MALL_ID || mallInfo.getMallId() == GameConfig.SUBSCRIBE_WEEK_CARD_MALL_ID){
            canBuy = GamePublicFunction.weekCardCanBuy(userId, mallInfo.getMallId());
        }
        if (canBuy) {
            return 0;
        } else {//不能购买，特权卡失效前一天才能买
            return GameErrorCode.E_MALL_LIMIT_BUY;
        }
    }
}
